package com.handu.luna.core.domain.promotion;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.handu.luna.core.domain.BaseRepository;

public interface CreditPromotionGoodsRepository extends JpaRepository<CreditPromotionGoods,Long>,BaseRepository<CreditPromotionGoods>,JpaSpecificationExecutor<CreditPromotionGoods> {
	
	@Query("from CreditPromotionGoods s  where s.creditPromotionId = :creditPromotionId order by s.id desc")
	Page<CreditPromotionGoods> findByCreditPromotionId(@Param("creditPromotionId") long creditPromotionId,Pageable pageable);
	
	@Query("from CreditPromotionGoods s  where s.creditPromotionId = :creditPromotionId AND goodsId = :goodsId ")
	CreditPromotionGoods findByCreditPromotionIdAndGoodsId(@Param("creditPromotionId") long creditPromotionId,@Param("goodsId") long goodsId);
	
	@Query("from CreditPromotionGoods s  where s.creditPromotionId = :creditPromotionId AND goodsId = :goodsId ")
	List<CreditPromotionGoods> findByCreidPromotionIdAndGoodsId(@Param("creditPromotionId") long creditPromotionId,@Param("goodsId") long goodsId);

    @Query("from CreditPromotionGoods s where s.creditPromotionId = ?1")
    List<CreditPromotionGoods> findByCreditPromotionId(long creditPromotionId);
	/*@Modifying
	@Query("delete from creditPromotionGoods s  where s.creditPromotionId = :creditPromotionId")
	public void deleteByPromotionId(@Param("creditPromotionId") int creditPromotionId);*/
}
